<?php
namespace app\user\controller\mall;

use app\common\controller\Userend;

class Base extends Userend {
    
    // 初始化
    public function __construct()
    {
        parent::__construct();

        $config = get_addon_config('mall');
        $replace_str = config('view_replace_str');
        $replace_str =  array_merge($replace_str,$this->view->engine->config('tpl_replace_string'));
        $this->view->engine->config('tpl_replace_string',array_merge($replace_str,
            [
                '__STYLE__' => $config['theme'],
                '__MALLCDN__' => $config['mallcdn']?$config['mallcdn']:config('view_replace_str.__CDN__'),
            ]
        ));
        $this->view->assign('config', $this->config);

        // 加载自定义标签库
        $this->view->engine->config('taglib_pre_load', 'addons\mall\taglib\Mall');

        \think\Config::set("mall",$config);

    }

    // 初始化
    public function _initialize() {
        parent::_initialize();
        if ($this->auth->isLogin()) {
            $user = $this->auth->getUser();
            $user->mall = \addons\mall\model\User::get($this->auth->id);

            $expire = input('post.keeplogin') ? 30 * 86400 : 0;
            $shop_id = \app\common\model\mall\shop\Shop::where("status", "normal")->getFieldByUserId($this->auth->id,"id");
            cookie('shop_id', $shop_id, $expire);
            $this->auth->set('shop_id',$shop_id);
            $this->view->assign('user', $user);
        }

    }

    public function selectpage()
    {
        return parent::selectpage();
    }

}